home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / disp186b.zip / VESAINFO.C < prev    next >
Text File  |  1994-03-20  |  6KB  |  166 lines

  1. /**
  2.  ** VESAINFO.H ---- routines to retrieve info from the VESA BIOS
  3.  **
  4.  ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5.  ** Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6.  ** Copyright (C) 1993 Grzegorz Mazur, gbm@ii.pw.edu.pl
  7.  **
  8.  ** This file is distributed under the terms listed in the document
  9.  ** "copying.dj", available from DJ Delorie at the address above.
  10.  ** A copy of "copying.dj" should accompany this file; if not, a copy
  11.  ** should be available from where this file was obtained.  This file
  12.  ** may not be distributed without a verbatim copy of "copying.dj".
  13.  **
  14.  ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  15.  ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16.  **/
  17.  
  18. /*
  19.  * VESA BIOS extended function number and return code
  20.  */
  21. #define VESA_FUNC    0x4f00
  22. #define VESA_SUCCESS    0x004f
  23.  
  24. #define VESA_VERSION(major,minor)    ((((major) & 0xff) << 8) | ((minor) & 0xff))
  25. #define VESA_VERSION_MAJOR(vers)    (((vers) >> 8) & 0xff)
  26. #define VESA_VERSION_MINOR(vers)    ((vers) & 0xff)
  27.  
  28. /*
  29.  * VESA BIOS sub-function numbers
  30.  */
  31. #define VESA_VGA_INFO    0        /* get VGA adapter info */
  32. #define VESA_MODE_INFO  1        /* get SVGA mode info */
  33. #define VESA_SET_MODE    2        /* set video mode */
  34. #define VESA_GET_MODE    3        /* get current video mode */
  35. #define VESA_VGA_STATE  4        /* save/restore VGA state */
  36. #define VESA_PAGE_CTL    5        /* memory control */
  37. /* VESA 1.1 +++ */
  38. #define VESA_SCAN_LNLEN 6        /* set/get scan line length */
  39. #define VESA_DISP_START 7        /* set/get display start address */
  40. /* VESA 1.2 +++ */
  41. #define VESA_PAL_CNTRL  8        /* DAC palette control */
  42.  
  43. /*
  44.  * The VGA info structure (without padding)
  45.  */
  46. typedef struct {
  47.     char        VESASignature[4];    /* should be "VESA" */
  48.     short        VESAVersion;    /* VESA version number */
  49.     char  far       *OEMStringPtr;    /* Pointer to OEM string */
  50.     long        Capabilities;    /* capabilities of the video env */
  51.     short far       *VideoModePtr;    /* ptr to supported Super VGA modes */
  52. } VgaInfoBlock;
  53.  
  54. /*
  55.  * The mode information structure (without padding)
  56.  */
  57. typedef struct {
  58.     short        ModeAttributes;    /* mode attributes */
  59.     char        WinAAttributes;    /* Window A attributes */
  60.     char        WinBAttributes;    /* Window B attributes */
  61.     short        WinGranularity;    /* window granularity */
  62.     short        WinSize;        /* window size */
  63.     unsigned short  WinASegment;    /* Window A start segment */
  64.     unsigned short  WinBSegment;    /* Window B start segment */
  65.     void     far   (*WinFuncPtr)();    /* pointer to window function */
  66.     short        BytesPerScanLine;    /* bytes per scan line */
  67.     /*
  68.      * extended information
  69.      * optional information
  70.      */
  71.     short        XResolution;    /* horizontal resolution */
  72.     short        YResolution;    /* vertical resolution */
  73.     char        XCharSize;        /* character cell width */
  74.     char        YCharSize;        /* character cell height */
  75.     char        NumberOfPlanes;    /* number of memory planes */
  76.     char        BitsPerPixel;    /* bits per pixel */
  77.     char        NumberOfBanks;    /* number of banks */
  78.     char        MemoryModel;    /* memory model type */
  79.     char        BankSize;        /* bank size in K */
  80.     char        NumImagePages;    /* number of image pages */
  81.     char        reserved[1];
  82.     /*
  83.      * VESA 1.2 and later
  84.      */
  85.     char        RedMaskSize;    /* number of bits in red mask */
  86.     char        RedMaskPos;        /* starting bit for red mask */
  87.     char        GreenMaskSize;
  88.     char        GreenMaskPos;
  89.     char        BlueMaskSize;
  90.     char        BlueMaskPos;
  91.     char        ReservedMaskSize;    /* reserved bits in pixel */
  92.     char        ReservedMaskPos;
  93.     char        DirectScreenMode;
  94. } ModeInfoBlock;
  95.  
  96. /*
  97.  * MODE attribute bits
  98.  */
  99. #define MODE_SUPPORTED  1        /* Mode supported in hardware */
  100. #define MODE_EXTINFO    2        /* Extended information available */
  101. #define MODE_SUPBIOS    4        /* Text output supported by BIOS */
  102. #define MODE_ISCOLOR    8        /* Monochrome/color mode */
  103. #define MODE_ISGRAPHICS 16        /* Mode type (0: text, 1:graphics) */
  104.  
  105. /*
  106.  * Window attribute bits
  107.  */
  108. #define WIN_SUPPORTED    1        /* Window supported */
  109. #define WIN_READABLE    2        /* Window readable */
  110. #define WIN_WRITABLE    4        /* Window writable */
  111.  
  112. /*
  113.  * MemoryModel values
  114.  */
  115. #define MODEL_TEXT    0        /* 00h = Text mode */
  116. #define MODEL_CGA    1        /* 01h = CGA graphics */
  117. #define MODEL_HERC       2        /* 02h = Hercules graphics */
  118. #define MODEL_4PLANE     3        /* 03h = 4-plane planar */
  119. #define MODEL_PACKED     4        /* 04h = Packed pixel */
  120. #define MODEL_256_NC     5        /* 05h = Non-chain 4, 256 color */
  121. #define MODEL_DIRECT     6        /* 06h = direct color mode */
  122. /* 07h-0Fh = Reserved, to be defined by VESA */
  123. /* 10h-FFh = To be defined by OEM         */
  124.  
  125. union {
  126.     VgaInfoBlock  _vgainfo;
  127.     char      _safety_buffer[270];
  128. } VESAVgaInfoBlock = {0};
  129.  
  130. union {
  131.     ModeInfoBlock _modeinfo;
  132.     char         _safety_buffer[270];
  133. } VESAModeInfoBlock = {0};    
  134.  
  135. int VESAversion = 0;
  136.  
  137. VgaInfoBlock *VESAgetInfo(void)
  138. {
  139.     _ES = FP_SEG(&VESAVgaInfoBlock._vgainfo);
  140.     _DI = FP_OFF(&VESAVgaInfoBlock._vgainfo);
  141.     _AX = VESA_FUNC + VESA_VGA_INFO;
  142.     geninterrupt(0x10);
  143.     if((_AX == VESA_SUCCESS) &&
  144.        (VESAVgaInfoBlock._vgainfo.VESASignature[0] == 'V') &&
  145.        (VESAVgaInfoBlock._vgainfo.VESASignature[1] == 'E') &&
  146.        (VESAVgaInfoBlock._vgainfo.VESASignature[2] == 'S') &&
  147.        (VESAVgaInfoBlock._vgainfo.VESASignature[3] == 'A')) {
  148.         VESAversion = VESAVgaInfoBlock._vgainfo.VESAVersion;
  149.         return(&VESAVgaInfoBlock._vgainfo);
  150.     }
  151.     return(0);
  152. }
  153.  
  154. ModeInfoBlock *VESAgetModeInfo(int mode)
  155. {
  156.     _ES = FP_SEG(&VESAModeInfoBlock._modeinfo);
  157.     _DI = FP_OFF(&VESAModeInfoBlock._modeinfo);
  158.     _CX = mode;
  159.     _AX = VESA_FUNC + VESA_MODE_INFO;
  160.     geninterrupt(0x10);
  161.     if(_AX != VESA_SUCCESS) return(0);
  162.     if((VESAModeInfoBlock._modeinfo.ModeAttributes & MODE_SUPPORTED) == 0) return(0);
  163.     return(&VESAModeInfoBlock._modeinfo);
  164. }
  165.  
  166.